﻿#region License
/* ---------------------------------------------------------------- *
 *
 * This file is part of the API Concepts Framework
 * http://apiconceptsframework.codeplex.com
 *
 * Copyright (C) 2014 eva Kühn, Thomas Scheller, Vienna University of Technology
 * http://www.complang.tuwien.ac.at/eva
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see http://www.gnu.org/licenses/
 *
 * ---------------------------------------------------------------- */
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using ApiConceptsFramework.HCs;

namespace ApiConceptsFramework.FluentApi
{
	/// <summary>
	/// Extension methods for the high-level concept fluent interface.
	/// </summary>
	public static class FluentInterfaceExtensions
	{
		/// <summary>
		/// For a fluent interface, defines a fluent method chain that is used. This needs to be defined in addition to the method calls.
		/// </summary>
		/// <typeparam name="T">The class that is used.</typeparam>
		/// <param name="eval">The ApiEvaluator instance.</param>
		/// <param name="methodChainExpr">Expression defining the method chain (starting from an instance class).</param>
		/// <param name="numberOfUsages">The number of usages (default = 1).</param>
		/// <param name="previousUsages">The number of previous usages (default = 0), used for calculating the learning effect.</param>
		public static void FluentMethodChain<T>(this ApiEvaluator eval, Expression<Action<T>> methodChainExpr, int numberOfUsages = 1, int previousUsages = 0)
		{
			var pd = eval.GetOrCreateHcInputData<FluentInterfaceInputData>();
			pd.FluentMethodChains.Add(new FluentMethodChain
			{
				Methods = methodChainExpr.GetChainedMethodInfos(),
				NumberOfUsages = numberOfUsages,
				PreviousUsages = previousUsages
			});
		}

		/// <summary>
		/// For a fluent interface, defines a fluent method chain that is used. This needs to be defined in addition to the method calls.
		/// </summary>
		/// <param name="eval">The ApiEvaluator instance.</param>
		/// <param name="methodChainExpr">Expression defining the method chain (starting from a static class).</param>
		/// <param name="numberOfUsages">The number of usages (default = 1).</param>
		/// <param name="previousUsages">The number of previous usages (default = 0), used for calculating the learning effect.</param>
		public static void FluentMethodChain(this ApiEvaluator eval, Expression<Action> methodChainExpr, int numberOfUsages = 1, int previousUsages = 0)
		{
			var pd = eval.GetOrCreateHcInputData<FluentInterfaceInputData>();
			pd.FluentMethodChains.Add(new FluentMethodChain
			{
				Methods = methodChainExpr.GetChainedMethodInfos(),
				NumberOfUsages = numberOfUsages,
				PreviousUsages = previousUsages
			});
		}
	}
}
